<?php
if (!defined('IN_ZWS')) exit();

class SettingAction extends PublicAction {
	function index() {
		header('Location:' . U('basic'));
	}

	function basic() {
		$setting = array('siteName' => setting('siteName'), 'siteDesc' => setting('siteDesc'), 'siteSubName' => setting('siteSubName'));
		$this -> assign($setting);
		$this -> display();
	}

	function mail() {
		$setting = array_merge(json_decode(setting('mailSetting'), true), array('verifyDeathTime' => setting('verifyDeathTime'), 'mgrMail' => setting('mgrMail')));
		$this -> assign($setting);
		$this -> display();
	}

	function vcode() {
		$setting = json_decode(setting('touclickSetting'), true);
		$this -> assign($setting);
		$this -> display();
	}

	function saveSetting() {
		switch ($this -> _get('type')) {
			case 1:
				if (setting('siteName', $this -> _post('siteName')) && setting('siteDesc' , $this -> _post('siteDesc')) && setting('siteSubName' , $this -> _post('siteSubName'))) $this -> ajaxReturn(array('redirect' => U('basic')), '保存成功！2秒钟后刷新本页面', 0);
				else $this -> ajaxReturn('', '保存失败！', 1);
				break;
			case 2:
				if (setting('mailSetting', json_encode(array('host' => $this -> _post('host'), 'address' => $this -> _post('address'), 'user' => $this -> _post('user'), 'pass' => $this -> _post('pass')))) && setting('verifyDeathTime', $this -> _post('verifyDeathTime')) && setting('mgrMail', $this -> _post('mgrMail'))) $this -> ajaxReturn(array('redirect' => U('mail')), '保存成功！2秒钟后刷新本页面', 0);
				else $this -> ajaxReturn('', '保存失败！', 1);
				break;
			case 3:
				if (setting('touclickSetting', json_encode(array('publicKey' => $this -> _post('publicKey'), 'privateKey' => $this -> _post('privateKey'))))) $this -> ajaxReturn(array('redirect' => U('vcode')), '保存成功！2秒钟后刷新本页面', 0);
				else $this -> ajaxReturn('', '保存失败！', 1);
				break;
			default:
				$this -> ajaxReturn('', '非法操作', 1);
		}
	}
}
